﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace PiscoSourServidor
{
    public class Program
    {
        static void Main()
        {
            IngresoOrdenCola();
            ConsultaOrdenColaIngresoBD();
        }

        public static void IngresoOrdenCola()
        {   
            IngresaOrden(2, "No muy caliente", 1, 4);
            IngresaOrden(2, "Poco ají", 1, 5);
        }


        /// <summary>
        /// Consulta la cola y la guarda la BD
        /// </summary>
        /// <returns></returns>
        public static string ConsultaOrdenColaIngresoBD()
        {
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Ordenes.svc/BDOrden");
            HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(httpRes.GetResponseStream());
            string strJson = strread.ReadToEnd();
            return strJson;
            
        }

        /// <summary>
        /// Ingresa ordenes a la cola
        /// </summary>
        /// <param name="cantidad"></param>
        /// <param name="obs"></param>
        /// <param name="reserva"></param>
        /// <param name="plato"></param>
        /// <returns></returns>
        public static string IngresaOrden(int cantidad, string obs, int reserva, int plato)
        {
            string strdata = "{\"intCantidad\":\"" + cantidad + "\",\"vchObservacion\":\"" + obs + "\",\"intCodPlato\":\"" + reserva + "\",\"intReserva\":\"" + plato + "\"}";
            byte[] btdata = Encoding.UTF8.GetBytes(strdata);
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Ordenes.svc/ColaOrden");
            httpReq.Method = "POST";
            httpReq.ContentLength = btdata.Length;
            httpReq.ContentType = "application/json";

            var reqStream = httpReq.GetRequestStream();
            reqStream.Write(btdata, 0, btdata.Length);

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strConsumoJson = strread.ReadToEnd();
            return strConsumoJson;
        }
    }
}
